
package all;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(urlPatterns = "/hkp/*")

public class CoreFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest)req;
        HttpServletResponse response = (HttpServletResponse)resp;
        String uri =request.getRequestURI();
        if ("/hkp/login.jsp".equals(uri) || uri.startsWith("/hkp/assets")){
            chain.doFilter(req,resp);
            return;
        }
        HttpSession session = request.getSession();
        Object uid = session.getAttribute("UID");
        if (uid == null){
            response.sendRedirect("/hkp/login.jsp");
            return;
        }
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
